const __method = {
    dowload: (imgsrc?: any, name?: any) => {//下载图片地址和图片名
        let image = new Image();
        // 解决跨域 Canvas 污染问题
        console.log(imgsrc, '222', name, '1231313131313')
        image.setAttribute("crossOrigin", "anonymous");
        image.onload = function () {
            console.log(121131313)
            let canvas: any = document.createElement("canvas");
            canvas.width = image.width;
            canvas.height = image.height;
            let context: any = canvas.getContext("2d");
            context.drawImage(image, 0, 0, image.width, image.height);
            let url: any = canvas.toDataURL("pptx"); //得到图片的base64编码数据
            let a: any = document.createElement("a"); // 生成一个a元素
            let event = new MouseEvent("click"); // 创建一个单击事件
            a.download = name || "photo"; // 设置图片名称
            a.href = url; // 将生成的URL设置为a.href属性
            a.dispatchEvent(event); // 触发a的单击事件
        };
        image.src = imgsrc;
    },
    print: () => {
        let oldStr = window.document.body.innerHTML; // 获取body的内容
        let start: any = "<!--startprint-->"; // 开始打印标识, 17个字符
        let end: any = "<!--endprint-->"; // 结束打印标识
        let newStr = oldStr.substr(oldStr.indexOf(start) + 17); // 截取开始打印标识之后的内容
        newStr = newStr.substring(0, newStr.indexOf(end)); // 截取开始打印标识和结束打印标识之间的内容
        window.document.body.innerHTML = newStr; // 把需要打印的指定内容赋给body
        window.print(); // 调用浏览器的打印功能打印指定区域
        window.document.body.innerHTML = oldStr; // body替换为原来的内容
    }
}
// const dowload2 = (url: any, name: any) => {
//     const img = new Image;
//     const canvas = document.createElement('canvas');
//     const ctx: any = canvas.getContext('2d');
//     img.onload = function() {
//         canvas.width = 200;
//         canvas.height = 200;
//         ctx.drawImage(this, 0, 0);

//         const elt = document.createElement('a');
//         elt.setAttribute('href', canvas.toDataURL('image/png'));
//         elt.setAttribute('download', name);
//         elt.style.display = 'none';
//         document.body.appendChild(elt);
//         elt.click();
//         document.body.removeChild(elt);
//     }
//     img.crossOrigin = 'anonymous';
//     img.src = url
// }
export default __method;